<template>
  <div id="BasciTools-map" style="width:100%;height:658px"></div>
  <div id="BasciTools-mapDiv" class="ol-popup">
    <!-- 显示控件 -->
    <div id="BasciTools-setDivPosition"  class="init-setDivPosition">
      <!-- 切换卫星和街道地图 -->
			<p @click="switchMap" class="init-setDivPosition-selected">
				<template v-if="switchMapBool==false">
					<img src="@/assets/map/image/weixing-b.png" title="切换卫星地图"><br/><span>卫星图</span>
				</template>
				<template v-else>
					<img src="@/assets/map/image/jiedao-b.png" title="切换街道地图"><br/><span>街道图</span>
				</template>
			</p>
			<!-- 返回主界面 -->
			<p @click="zoomDefaultPosition" :class="{ 'init-setDivPosition-selected': zoomDefaultPositionBool==true }">
				<img src="@/assets/map/image/newImage/home.png" title="返回主界面"><br/><span>主界面</span>
			</p>
			<!-- 显示工具箱 -->
			<p @click="showHideToolsBoxDiv" :class="{ 'init-setDivPosition-selected': showHideToolsBox==false }">
				<template v-if="showHideToolsBox">
					<img src="@/assets/map/image/tools.png" title="打开工具箱"><br/><span>工具箱</span>
				</template>
				<template v-else>
					<img src="@/assets/map/image/tools.png" title="关闭工具箱"><br/><span>工具箱</span>
				</template>
			</p>
      <!-- 图件生成 -->
      <p @click="showImgcreate" :class="{ 'init-setDivPosition-selected': showImgcreateBool==true }">
        <img src="@/assets/map/image/newImage/icon-imgcreate.png" title="生成图件"><br/><span style="border:0;">生成图件</span>
      </p>
    </div>
    <!-- 工具箱 -->
		<div id="BasciTools-ToolsBoxDiv" class="init-ToolsBoxDiv">
			<p @click="measureToolBox" :class="{ 'init-setDivPosition-selected': showHideMeasureTool==false }">
				<template v-if="showHideMeasureTool">
					<img title="开启测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
				</template>
				<template v-else>
					<img title="关闭测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
				</template>
			</p>
			<p @click="positionToolBox" :class="{ 'init-setDivPosition-selected': showHidePositionTool==false }">
        <template v-if="showHidePositionTool">
          <img title="开启定位工具" src="@/assets/map/image/dingw.png"><br/>
          <template v-if="paramsSql.layerType=='功能失效分析图'">
            <span>定位</span>
          </template>
          <template v-else>
            <span style="border:0;">定位</span>
          </template>
        </template>
        <template v-else>
          <img title="关闭定位工具" src="@/assets/map/image/dingw.png"><br/>
          <template v-if="paramsSql.layerType=='功能失效分析图'">
            <span>定位</span>
          </template>
          <template v-else>
            <span style="border:0;">定位</span>
          </template>
        </template>
      </p>
      <template v-if="paramsSql.layerType=='功能失效分析图'">
        <p @click="networkToolBox" :class="{ 'init-setDivPosition-selected': showHideNetworkTool==false }">
          <template v-if="showHideNetworkTool">
            <img title="开启网络分析工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">网络分析</span>
          </template>
          <template v-else>
            <img title="开启网络分析工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">网络分析</span>
          </template>
        </p>
      </template>
		</div>
    <!-- 所有工具 -->
    <div id="BasciTools-AllToolsDiv" class="init-AllToolsDiv">
      <!-- 测量工具 -->
      <div id="BasciTools-MeasureToolsDiv" class="init-AllToolsDivFloat">
        <p @click="measureDistance" :class="{ 'init-setDivPosition-selected': measureDistanceBool==false }">
          <template v-if="measureDistanceBool">
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="measureArea" :class="{ 'init-setDivPosition-selected': measureAreaBool==false }">
          <template v-if="measureAreaBool">
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="stopMeasure" :class="{ 'init-setDivPosition-selected': stopMeasureBool==false }">
          <template v-if="stopMeasureBool">
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="clearMeasure" :class="{ 'init-setDivPosition-selected': clearMeasureBool==false }">
          <template v-if="clearMeasureBool">
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
        </p>
      </div>
      <!-- 定位工具 -->
      <div id="BasciTools-MousePositionDiv">
        <span><img class="init-jingd" src="@/assets/map/image/jingd.png" title="鼠标左键在地图上点击位置的经度值"></span>
        <input id="BasciTools-MousePositionLon" type="text" value="">
        <span><img class="init-weid" src="@/assets/map/image/weid.png" title="鼠标左键在地图上点击位置的纬度值"></span>
        <input id="BasciTools-MousePositionLat" type="text" value="">
        <p @click="clearPosition" :class="{ 'init-setDivPosition-selected': clearPositionBool==false }">
          <template v-if="clearPositionBool">
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="addPosition" :class="{ 'init-setDivPosition-selected': addPositionBool==false }">
          <template v-if="addPositionBool">
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
        </p>
      </div>
      <!-- 超图设施网络分析工具 -->
      <div id="BasciTools-NetworkDiv">
        <span style="position: relative;top: 20px;padding: 10px;color: white;">查询类型</span>
        <!--<input id="BasciTools-networkType" type="text" value="POINT" style="top:20px;">-->
        <select id="BasciTools-networkType" style="position: relative;top: 20px;height: 33px;">
          <option value="POINT">点数据</option>
          <option value="LINE">线数据</option>
        </select>
        <span style="position: relative;top: 20px;padding: 10px;color: white;">查询ID</span>
        <input id="BasciTools-networkId" type="text" value="1" style="top:20px;">
        <span style="position: relative;top: 20px;padding: 10px;color: white;">无效ID</span>
        <input id="BasciTools-notValidNetworkId" type="text" value="1" style="top:20px;">
        <p @click="addNetworkAnalystLayer(true,null)">
          <img src="@/assets/map/image/newImage/search.png" title="查询设施"><br/><span>查询设施</span>
        </p>
        <p @click="queryNetworkSourceNodeIDs">
          <img src="@/assets/map/image/newImage/search.png" title="查询源点"><br/><span>查询源点</span>
        </p>
        <p @click="setNetworkNotValidId">
          <img src="@/assets/map/image/newImage/search.png" title="设置无效"><br/><span>设置无效</span>
        </p>
        <p @click="traceDownAnalyst(true,null)">
          <img src="@/assets/map/image/newImage/search.png" title="下游追踪"><br/><span>下游追踪</span>
        </p>
        <p @click="traceUpAnalyst(true,null)">
          <img src="@/assets/map/image/newImage/search.png" title="上游追踪"><br/><span>上游追踪</span>
        </p>
        <p @click="burstAnalyse">
          <img src="@/assets/map/image/newImage/search.png" title="爆管分析"><br/><span>爆管分析</span>
        </p>
        <p @click="networkConnectededgesAnalyst">
          <img src="@/assets/map/image/newImage/search.png" title="连通性分析"><br/><span>连通性分析</span>
        </p>
        <p @click="clearNetwork">
          <img src="@/assets/map/image/qux.png" title="清空全部网络分析结果"><br/><span>清空结果</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
import Map from 'ol/Map';
import View from 'ol/View';
import VectorLayer from 'ol/layer/Vector';
import {Vector as VectorSource} from 'ol/source'
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import {Select, Draw, Modify, Snap, Translate} from 'ol/interaction';
import {unByKey} from 'ol/Observable';
import Circle from 'ol/geom/Circle';
import CircleDraw from 'ol/geom/Circle';
import {fromCircle} from 'ol/geom/Polygon';
import Overlay from 'ol/Overlay';
import Polygon from 'ol/geom/Polygon';
import LineString from 'ol/geom/LineString';
import {getArea, getLength} from 'ol/sphere';
import {Fill, Stroke, Style, Icon, Circle as CircleStyle,Text} from 'ol/style';
import WKT from 'ol/format/WKT';
import dingweiImg from '@/assets/map/image/newImage/blueMarker.png';
import { getProjection,iServerHttp,getRESTLayer, getTiandituVecMap,getChinaBoundaryLayer, getTiandituVecText,getTiandituImgMap, getTiandituImgText,getNetworkLayer,meterToDegree } from "@/map/projMap.js";
import { MapService,GetFeaturesByGeometryParameters,FeatureService} from "@supermap/iclient-ol";
import { mapSqlQueryResultsPost, networkTracedown, networkTraceup, networkBurstanalyse, networkConnectededges } from '@/api/lifelineProject/index'
import { getNetworkVersionList } from "@/api/lifelineProject/networkdataset.js"
import {boundingExtent} from 'ol/extent';
import {ElMessage,ElLoading} from "element-plus";

export default({
  name: 'BasicToolMap',
  props:{
    paramsSql: {//全部序号列表
      type:Object,
      required:true,
      default:{}
    },
    closeImgcreate: {//关闭生成图件
      type:Boolean,
      required:true,
      default:false
    },
  },
  emits:["showImgcreate","getLegendHtml"],
  data(){
    return {
      str: 'BasciTools',
      map: null,
      center: [105, 34],
      zoom: 4,
      layer1: null,
      layer2: null,
      layer3: null,
      layer4: null,
      source: null,// 矢量绘制图层
      measure: null,
      measureSource: null,// 测量结果图层
      switchMapBool: false, // 卫星图
      zoomDefaultPositionBool: true,// 返回主界面
      showHideToolsBox: true,// 工具箱
      showHideMeasureTool:true,//显示|隐藏测量工具
      showHidePositionTool: true,// 定位工具
      measureDistanceBool: true,
      measureAreaBool: true,
      stopMeasureBool: true,
			clearMeasureBool: true,
      clearPositionBool: true,
			addPositionBool: true,
      helpTooltipElement:null,
      helpTooltip:null,
      measureTooltipElement:null,
      measureTooltip:null,
      measureTooltipArray:[],//全部测量结果Overlay数组
      showImgcreateBool:false,//是否打开生成图件按钮
      html: '',
      //网络分析
      showHideNetworkTool:true,//网络分析工具
      networkFeatureLayer:null,//查询要素图层
      networkAnalystLayer:null,//网络分析结果图层
      tempNetworkNodeIdArray:[],//用于查询下游追踪分析的节点ID
      tempNetworkEdgeIdArray:[],//用于查询下游追踪分析的弧段ID
      featureNetworkNodeIdArray:[],//查询结果绘制节点ID
      featureNetworkEdgeIdArray:[],//查询结果绘制弧段ID
      notValidNetworkNodeIdArray:[],//无效节点ID
      notValidNetworkEdgeIdArray:[],//无效弧段ID
      sourceNodeIDsArray:[],//源点ID数组
      sourceNodeIDs:"",//源点ID数组字符串
      networkDatasource:"",//网络分析数据源
      networkDataset:"",//网络分析数据集
      networkUrl:"",//网络分析服务url
      networkMapUrl:"",//网络分析地图服务url
      popupInfoLayer:null,//弹出窗口
      clearNetworkBool:true,//清空网络分析结果
      //用于图层查询
      allDataTypeInfoArray:[],//图层信息类型数组
      showLayerNum:0,//当前显示的图层数量
      queryLayerNum:0,//已查询的图层数量
      resultDataTypeInfo:null,//已查询到图层要素结果的数据类型信息
      resultDataId:null,//已查询到的图层要素主键ID
      resultDataFeature:null,//已查询到的图层要素数据
      selectFeatureLayer:null,//选中要素高亮显示图层
      loading:null,//是否正在查询
    }
  },
  watch: {
    paramsSql: {//地图对象
      handler: function(newVal,oldVal){
        if(newVal!=oldVal){

        }
      },
      immediate:true
    },
    closeImgcreate: {//关闭生成图件
      handler: function(newVal,oldVal){
        if(newVal!=oldVal){
          if(newVal==false){
            this.showImgcreateBool = false;
          }
        }

      },
      immediate:true
    },
  },
  mounted(){
    let that = this
    this.$nextTick(function(){
      setTimeout(() => {
        // 初始化地图
        that.initMap()
        that.initAddLayer();//初始化加载图层数据
      }, 200)
    })
  },
  methods: {
    initMap() {
      let that = this
      let targetMap = document.getElementById(this.str + '-map')
      // 清空targetMap
      targetMap.innerHTML = ''
      //新建popup弹窗
      let targetDiv = document.getElementById(this.str+"-mapDiv");
      let node = document.createElement("div");
      node.id = this.str+"-popup";
      node.setAttribute("class","new-ol-popup");
      node.innerHTML = '<a href="#" id="'+this.str+'-popup-closer" class="new-ol-popup-closer"></a>' +
          '<div id="'+this.str+'-popup-content" style="max-height: 300px;overflow-y: auto;overflow-x: hidden;"></div>';
      targetDiv.appendChild(node);
      console.log("新建popup");
      // 获取地图div的高度
      this.autodivheight()
      // 浏览器窗口发生变化时同时变化DIV高度
      window.onresize = this.autodivheight()
      if (this.map){ //避免地图重复加载
        return
      }
      //获取投影4490坐标系
      this.projection4490 = getProjection();
      //初始化地图信息
      this.map = new Map({
        target: targetMap.id,
        view: new View({
          center: this.center,
          maxZoom: 18,
          minZoom: 4,
          zoom: this.zoom,
          constrainResolution:true,//缩放地图可移动到最近的缩放级别（整数zoom级别）
          projection: 'EPSG:4490',
        })
      });
      this.layer1 = getTiandituVecMap()
      this.map.addLayer(this.layer1)
      this.layer2 = getTiandituVecText()
      this.map.addLayer(this.layer2)
      this.layer1.setZIndex(0)
      this.layer2.setZIndex(0)
      //矢量绘制图层
      this.source = new VectorSource({
        wrapX: false
      });
      let vectorLayer = new VectorLayer({
        source: that.source,
        projection: 'EPSG:4490'
      });
      this.map.addLayer(vectorLayer);
      vectorLayer.setZIndex(2);
      //测量结果图层
      this.measureSource = new VectorSource({
        wrapX: false
      });
      let measureLayer = new VectorLayer({
        source: that.measureSource,
        projection: 'EPSG:4490'
      });
      this.map.addLayer(measureLayer);

      //查询设施网络数据图层
      this.networkFeatureLayer = new VectorLayer({
        source: new VectorSource({
          wrapX: false
        }),
        projection: 'EPSG:4490'
      });
      this.map.addLayer(this.networkFeatureLayer);
      this.networkFeatureLayer.setZIndex(3);

      //网络分析查询结果图层
      this.networkAnalystLayer = new VectorLayer({
        source: new VectorSource({
          wrapX: false
        }),
        projection: 'EPSG:4490'
      });
      this.map.addLayer(this.networkAnalystLayer);
      this.networkAnalystLayer.setZIndex(2);

      //选中要素高亮显示图层
      this.selectFeatureLayer = new VectorLayer({
        source: new VectorSource({
          wrapX: false
        }),
        projection: 'EPSG:4490'
      });
      this.map.addLayer(this.selectFeatureLayer);
      this.selectFeatureLayer.setZIndex(50);

      //弹出窗口
      let popupTarget = document.getElementById(this.str+"-popup");
      if(popupTarget){
        this.popupInfoLayer = new Overlay({
          element: popupTarget,
          positioning: 'center-center'
        });
        this.map.addOverlay(this.popupInfoLayer);
        //显示弹出窗口
        document.getElementById(this.str+"-popup").style.display="block";
        //关闭弹出事件
        document.getElementById(this.str+"-popup-closer").onclick = function () {
          that.popupInfoLayer.setPosition(undefined);
          //隐藏弹出窗口
          document.getElementById(that.str+"-popup").style.display="none";
        };
      }

      //地图移动事件
      this.map.on('moveend', function (event) {
        let center = that.map.getView().getCenter();
        let zoom = that.map.getView().getZoom();
        if(center[0]!=that.center[0] || center[1]!=that.center[1] || zoom!=that.zoom){
          //设置主界面图标文字
          that.zoomDefaultPositionBool = false;
        }else{//主界面
          //设置主界面图标文字
          that.zoomDefaultPositionBool = true;
        }
      });
      // getChinaBoundaryLayer(this.map)
      this.map.on('click', function(event){
        let coordinate = that.map.getEventCoordinate(event.originalEvent)
        if (that.showHidePositionTool == false) {
          document.getElementById(that.str + '-MousePositionLon').value = coordinate[0]
          document.getElementById(that.str + '-MousePositionLat').value = coordinate[1]
        }
        //隐藏弹出窗口
        if (that.popupInfoLayer != null) {
          that.popupInfoLayer.setPosition(undefined);
        }
        let pixel = that.map.getEventPixel(event.originalEvent);
        let feature = that.map.forEachFeatureAtPixel(pixel, function (feature) {
          //根据像素坐标获取右键选中的地图要素
          return feature;
        });
        if (feature && that.draw == null) {
          //选中要素
          that.selectFeature = feature;
          //属性信息
          let temp = feature.getProperties();
          if(temp.type=="networkResult") {//网络分析结果
            console.log("查看网络分析属性："+temp);
            //设置弹窗内容
            that.setPopupContent(temp);
            that.popupInfoLayer.setPosition(coordinate);
          }
        }else{
          if(that.draw==null && that.measure==null){
            //根据经纬度查询当前显示的图层要素数据
            that.getAllShowLayerFeatureDataByLonLat(coordinate);
          }
        }
      })
    },
    initAddLayer(){//初始化加载图层数据
      let newVal = this.paramsSql;
      if(JSON.stringify(newVal) != '{}'){
        //缩放到区域位置
        if(newVal.extentLonLatList.length>0){
          this.showBoundingExtent(newVal.extentLonLatList);
        }
        this.$emit("getLegendHtml",null);
        this.addResultLayerLine(newVal);//线数据图层
        this.addResultLayer(newVal);//点数据图层
        this.getNetworkVersion(newVal);//获取网络分析服务
        let that = this;
        setTimeout(function(){
          //缩放到区域位置
          if(newVal.extentLonLatList.length>0){
            that.showBoundingExtent(newVal.extentLonLatList);
          }
        },1000);
      }
    },
    addResultLayer(params) {//点数据图层
      let layerUrl = ''
      if(params.layerType=="破坏等级分析图"){
        if(params.seismicInputMode=="0"){
          if(params.intensity == 'ld1') {
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_6@fxfzfxqh'
          }else if(params.intensity == 'ld2'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_7@fxfzfxqh'
          }else if(params.intensity == 'ld3'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_8@fxfzfxqh'
          }else if(params.intensity == 'ld4'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_9@fxfzfxqh'
          }else if(params.intensity == 'ld5'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_10@fxfzfxqh'
          }
        }else{
          layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_influence@fxfzfxqh'
        }
      }else if(params.layerType=="功能失效分析图"){
        if(params.seismicInputMode=="0"){
          if(params.intensity == 'ld1') {
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_6_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld2'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_7_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld3'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_8_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld4'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_9_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld5'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_10_failureLevel@fxfzfxqh'
          }
        }else{
          layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_influence_failureLevel@fxfzfxqh'
        }
      }
      let sqlText = []
      if(params.type.name == '供水系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='1' and del_flag='0'");//地下管网
        // sqlText.push("task_id = '" + params.taskId + "' and type ='2' and del_flag='0'");//水厂水池
        // sqlText.push("task_id = '" + params.taskId + "' and type ='11' and del_flag='0'");//水厂泵房
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='1' or type ='2' or type ='11')");//地下管网、水厂水池、水厂泵房
      }else if(params.type.name == '供气系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='3' and del_flag='0'");//燃气储气罐
        // sqlText.push("task_id = '" + params.taskId + "' and type ='14' and del_flag='0'");//燃气门站
        // sqlText.push("task_id = '" + params.taskId + "' and type ='15' and del_flag='0'");//供气管网
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='3' or type ='14' or type ='15')");//燃气储气罐、燃气门站、供气管网
      }else if(params.type.name == '供电系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='6' and del_flag='0'");//变电站
        // sqlText.push("task_id = '" + params.taskId + "' and type ='12' and del_flag='0'");//重要发电厂房
        // sqlText.push("task_id = '" + params.taskId + "' and type ='8' and del_flag='0'");//电缆线路
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='6' or type ='12' or type ='8')");//变电站、重要发电厂房、电缆线路
      }else if(params.type.name == '交通系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='5' and del_flag='0'");//道路
        // sqlText.push("task_id = '" + params.taskId + "' and type ='4' and del_flag='0'");//桥梁
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='5' or type ='4')");//道路、桥梁
      }else if(params.type.name== '通信系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='9' and del_flag='0'");//通信室内设备
        // sqlText.push("task_id = '" + params.taskId + "' and type ='13' and del_flag='0'");//通信基站
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='9' or type ='13')");//通信室内设备、通信基站
      }
      for(let i = 0;i < sqlText.length;i++) {
        this.createRestMapTempLayersSet(layerUrl,sqlText[i],i,sqlText.length);
        let obj = {
          database:"fxfzfxqh",
          name: '生命线计算结果点数据图层',
          code: 'smxResultLine',
          table:"fxqh_smx_evaluation_results",
          url:layerUrl,
          zIndex:8,
          fieldId:"id",
          sqlText:sqlText[i],
          seismicInputMode:params.seismicInputMode,
          intensity:params.intensity,
          type:params.type.name
        };
        this.allDataTypeInfoArray.push(obj);
      }
    },
    addResultLayerLine(params) {//线数据图层
      let layerUrl = ''
      if(params.layerType=="破坏等级分析图"){
        if(params.seismicInputMode=="0"){
          if(params.intensity == 'ld1') {
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_6@fxfzfxqh'
          }else if(params.intensity == 'ld2'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_7@fxfzfxqh'
          }else if(params.intensity == 'ld3'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_8@fxfzfxqh'
          }else if(params.intensity == 'ld4'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_9@fxfzfxqh'
          }else if(params.intensity == 'ld5'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_10@fxfzfxqh'
          }
        }else{
          layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_line_influence@fxfzfxqh'
        }
      }else if(params.layerType=="功能失效分析图"){
        if(params.seismicInputMode=="0"){
          if(params.intensity == 'ld1') {
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_6_line_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld2'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_7_line_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld3'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_8_line_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld4'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_9_line_failureLevel@fxfzfxqh'
          }else if(params.intensity == 'ld5'){
            layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_10_line_failureLevel@fxfzfxqh'
          }
        }else{
          layerUrl = iServerHttp() + '/iserver/services/map-fxfzfxqh/rest/maps/fxqh_smx_evaluation_results_influence_line_failureLevel@fxfzfxqh'
        }
      }
      if(layerUrl==''){
        return;
      }
      let sqlText = []
      if(params.type.name == '供水系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='1' and del_flag='0'");//地下管网
        // sqlText.push("task_id = '" + params.taskId + "' and type ='2' and del_flag='0'");//水厂水池
        // sqlText.push("task_id = '" + params.taskId + "' and type ='11' and del_flag='0'");//水厂泵房
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='1' or type ='2' or type ='11')");//地下管网、水厂水池、水厂泵房
      }else if(params.type.name == '供气系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='3' and del_flag='0'");//燃气储气罐
        // sqlText.push("task_id = '" + params.taskId + "' and type ='14' and del_flag='0'");//燃气门站
        // sqlText.push("task_id = '" + params.taskId + "' and type ='15' and del_flag='0'");//供气管网
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='3' or type ='14' or type ='15')");//燃气储气罐、燃气门站、供气管网
      }else if(params.type.name == '供电系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='6' and del_flag='0'");//变电站
        // sqlText.push("task_id = '" + params.taskId + "' and type ='12' and del_flag='0'");//重要发电厂房
        // sqlText.push("task_id = '" + params.taskId + "' and type ='8' and del_flag='0'");//电缆线路
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='6' or type ='12' or type ='8')");//变电站、重要发电厂房、电缆线路
      }else if(params.type.name == '交通系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='5' and del_flag='0'");//道路
        // sqlText.push("task_id = '" + params.taskId + "' and type ='4' and del_flag='0'");//桥梁
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='5' or type ='4')");//道路、桥梁
      }else if(params.type.name== '通信系统数据源选择') {
        // sqlText.push("task_id = '" + params.taskId + "' and type ='9' and del_flag='0'");//通信室内设备
        // sqlText.push("task_id = '" + params.taskId + "' and type ='13' and del_flag='0'");//通信基站
        sqlText.push("task_id = '" + params.taskId + "' and del_flag='0' and (type ='9' or type ='13')");//通信室内设备、通信基站
      }
      for(let i = 0;i < sqlText.length;i++) {
        this.createRestMapTempLayersSet(layerUrl,sqlText[i],i,sqlText.length);
        let obj = {
          database:"fxfzfxqh",
          name: '生命线计算结果线数据图层',
          code: 'smxResultLine',
          table:"fxqh_smx_evaluation_results_line",
          url:layerUrl,
          zIndex:7,
          fieldId:"id",
          sqlText:sqlText[i],
          seismicInputMode:params.seismicInputMode,
          intensity:params.intensity,
          type:params.type.name
        };
        this.allDataTypeInfoArray.push(obj);
      }
    },
    createRestMapTempLayersSet(layerUrl,sqlText,i,length){//查询REST图层信息并创建新的临时图层
      let url = encodeURI(layerUrl +"/layers.rjson");
      let that = this;
      //查询REST图层信息
      let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
      httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中
      httpRequest.send();//第三步：发送请求  将请求参数写在URL中
      //获取数据后的处理程序
      httpRequest.onreadystatechange = function () {
        if (httpRequest.readyState == 4 && httpRequest.status == 200) {
          let json = httpRequest.responseText;//获取到json字符串，还需解析
          let obj = JSON.parse(json);
          if(obj.length>0){
            if(sqlText!=null && sqlText!=""){
              for(let i=0;i<obj.length;i++){
                let layers = obj[i].subLayers.layers;
                for(let j=0;j<layers.length;j++){
                  layers[j].displayFilter = sqlText;//SQL查询过滤
                }
              }
            }
            that.postTempLayersSet(layerUrl,obj,i,length);//创建并获取超图临时图层
          }
        }
      };
    },
    postTempLayersSet(layerUrl,obj,i,length){//创建并获取超图临时图层
      let that = this;
      let url = encodeURI(layerUrl+"/tempLayersSet.rjson");
      let entry = JSON.stringify(obj);
      let xhr = new XMLHttpRequest();//第一步：建立所需的对象
      xhr.open("POST", url, true);//第二步：打开连接  将请求参数写在url中
      xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      //获取数据后的处理程序
      xhr.onreadystatechange = function(){
        let readyState = xhr.readyState;
        if (readyState == 4){
          let status = xhr.status;
          let responseText =  xhr.responseText ;
          let result = JSON.parse(responseText);
          if(result.succeed){
            let layerID = result.newResourceID
            //根据layerUrl、临时图层layerID和zIndex查询并添加瓦片地图图层REST
            that.createMapRestLayer(layerUrl,layerID,i,length);
          }
          xhr.onreadystatechange = function(){};
          xhr = null;
        }
      };
      xhr.send(entry);//第三步：发送请求  将请求参数写在URL中
    },
    //REST图层查询
    createMapRestLayer(layerUrl,layerID,i,length){//根据layerUrl、临时图层layerID和zIndex查询并添加瓦片地图图层REST
      let that = this;
      //瓦片地图图层
      let mapService = new MapService(layerUrl);//根据超图REST图层获取图层信息
      mapService.getMapInfo(function (serviceResult) {
        if(serviceResult.result!=undefined){
          let mapJSONObj = serviceResult.result;
          let layerName = mapJSONObj.name;//图层名称
          //获取图层范围
          let bounds = mapJSONObj.bounds;
          let left = bounds.left;
          let bottom = bounds.bottom;
          let right = bounds.right;
          let top = bounds.top;
          let origin = [left, top];//左上角
          let extent = [left, bottom, right, top];//图层范围
          //获取超图发布的REST图层（自定义比例尺）
          let layer = getRESTLayer(layerUrl,layerID,origin,extent,mapJSONObj,17);
          that.map.addLayer(layer);
          //缩放到图层范围
          that.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
          //图层范围
          let bbox = extent.join(",");
          //获取图例
          if(i == length - 1) {
            that.getLayerLegend('',layerUrl,bbox);//根据url获取图层图例信息
          }
        }
      });
    },
    getLayerLegend(realName,layerUrl,bbox){//根据url获取图层图例信息
      let that = this;
      layerUrl += '/legend.json?bbox=' + bbox;
      layerUrl += '&returnVisibleOnly=false';//是否只返回当前地图范围内可见要素的图例。默认为 false
      //图层图例信息查询
      let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
      httpRequest.open('GET', layerUrl, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
      httpRequest.send();//第三步：发送请求  将请求参数写在URL中
      /**
       * 获取数据后的处理程序
       */
      httpRequest.onreadystatechange = function () {
        if (httpRequest.readyState == 4 && httpRequest.status == 200) {
          let json = httpRequest.responseText;//获取到json字符串，还需解析
          let obj = JSON.parse(json);
          let layerLegends = obj.layerLegends;
          if(layerLegends!=null && layerLegends.length>0){
            let html = '';
            for(let i=0;i<layerLegends.length;i++){
              let layerLegend = layerLegends[i];
              //获取图层名称
              let layerName = layerLegend.layerName;
              let legends = layerLegend.legends;
              if(legends!=null && legends.length>0){
                if(layerName.indexOf("#")!=-1 && legends.length==1){
                  let textImgUrl = iServerHttp() + "/iserver/manager/static/Theme/image/LabelUniform.png";
                  //文字图层不显示图例
                  if(legends[0].url==textImgUrl){
                    continue;
                  }
                }
                if(legends.length>1){//多图例图层
                  html += '<p style="text-align: center;font-weight: bold;">'+realName+'</p>';
                  for(let j=0;j<legends.length;j++){
                    let legend = legends[j];
                    let values = legend.values;
                    if(values==null){
                      continue;
                    }
                    let imageData = legend.imageData;
                    let contentType = legend.contentType;
                    let url = legend.url;
                    let label = legend.label;
                    let width = legend.width;
                    let height = legend.height;
                    let imgSrc = "data:image/jpeg;base64,"+imageData;
                    html += '<p style="height: '+height+'px;">';
                    html += '<img style="width:'+width+'px;height:'+height+'px" src="'+imgSrc+'" />';
                    html += '<span style="position: relative;top: -2px;left: 10px;height: 16px;font-size: 16px;">'+label+'</span>';
                    html += '</p>';
                  }
                }else{//单一图例图层
                  let legend = legends[0];
                  let values = legend.values;
                  let imageData = legend.imageData;
                  let contentType = legend.contentType;
                  let url = legend.url;
                  let label = legend.label;
                  let width = legend.width;
                  let height = legend.height;
                  let imgSrc = "data:image/jpeg;base64,"+imageData;
                  html += '<p style="height: '+height+'px;">';
                  html += '<img style="width:'+width+'px;height:'+height+'px" src="'+imgSrc+'" />';
                  html += '<span style="position: relative;top: -2px;left: 10px;height: 16px;font-size: 16px;">'+realName+'</span>';
                  html += '</p>';
                }
              }
            }
            //图例html
            that.$emit("getLegendHtml",{name:realName,legendHtml:html,show:true});
          }
        }
      };
    },
    showImgcreate(){//生成图件
      if(this.showImgcreateBool){
        this.showImgcreateBool = false;
        this.$emit("showImgcreate",false);
      }else{
        this.showImgcreateBool = true;
        this.$emit("showImgcreate",true);
      }
    },
    // 街道图与卫星图切换
    switchMap() {
      if (this.switchMapBool) {// 显示街道图
        this.switchMapBool = false
        if (this.layer1 == null) {
          this.layer1 = getTiandituVecMap()
          this.map.addLayer(this.layer1)
        }
        if (this.layer2 == null) {
          this.layer2 = getTiandituVecText()
          this.map.addLayer(this.layer2)
        }
        this.layer1.setVisible(true);
        this.layer2.setVisible(true);
        this.layer3.setVisible(false);
        this.layer4.setVisible(false);
        this.layer1.setZIndex(0);
        this.layer2.setZIndex(0);
      } else {
        this.switchMapBool = true
        if (this.layer3 == null) {
          this.layer3 = getTiandituImgMap()
          this.map.addLayer(this.layer3)
        }
        if (this.layer4 == null) {
          this.layer4 = getTiandituImgText()
          this.map.addLayer(this.layer4)
        }
        this.layer1.setVisible(false)
        this.layer2.setVisible(false)
        this.layer3.setVisible(true)
        this.layer4.setVisible(true)
        this.layer3.setZIndex(0)
        this.layer4.setZIndex(0)
      }
    },
    zoomDefaultPosition() {// 返回主界面
      this.map.updateSize();
      this.map.getView().setCenter(this.center);
      this.map.getView().setZoom(this.zoom);
      this.zoomDefaultPositionBool = true;
    },
    showHideToolsBoxDiv() {// 显示工具箱
      if (this.showHideToolsBox) {
        this.showHideToolsBox = false
        document.getElementById(this.str + '-ToolsBoxDiv').style.display = 'block'
      } else {
        this.showHideToolsBox = true
        document.getElementById(this.str + '-ToolsBoxDiv').style.display = 'none'
      }
    },
    measureToolBox() {
      if (this.showHideMeasureTool) {
        this.showHideMeasureTool = false
        document.getElementById(this.str + '-MeasureToolsDiv').style.display = 'block'
      } else {
        this.showHideMeasureTool = true
        document.getElementById(this.str + '-MeasureToolsDiv').style.display = 'none'
      }
    },
    positionToolBox() {
      if (this.showHidePositionTool) {
        this.showHidePositionTool = false
        document.getElementById(this.str + '-MousePositionDiv').style.display = 'block'
      } else {
        this.showHidePositionTool = true
        document.getElementById(this.str + '-MousePositionDiv').style.display = 'none'
      }
    },
    measureDistance() {
      if(this.source!=null){
        //地图工具箱--开启测距
        this.setMapToolBox('MeasureDistance');
        //设置样式
        this.measureDistanceBool = false;
        this.measureAreaBool = true;
        this.stopMeasureBool = true;
        this.clearMeasureBool = true;
      }
    },
    measureArea() {
      if(this.source!=null){
        //地图工具箱--开启测面
        this.setMapToolBox('MeasureArea');
        //设置样式
        this.measureAreaBool = false;
        this.measureDistanceBool = true;
        this.stopMeasureBool = true;
        this.clearMeasureBool = true;
      }
    },
    stopMeasure() {
      if(this.source!=null){
        //地图工具箱--停止测量
        this.setMapToolBox('StopMeasure');
        //设置样式
        this.stopMeasureBool = false;
        this.measureDistanceBool = true;
        this.measureAreaBool = true;
        this.clearMeasureBool = true;
      }
    },
    clearMeasure () {
      if(this.source!=null){
        //地图工具箱--清空测量结果
        this.setMapToolBox('ClearMeasure');
        //设置样式
        this.clearMeasureBool = false;
        this.measureDistanceBool = true;
        this.measureAreaBool = true;
        this.stopMeasureBool = true;
      }
    },
    clearPosition() {
      this.clearPositionBool = false;
      this.addPositionBool = true;
      //地图工具箱--清空
      this.setMapToolBox("Clear");
    },
    addPosition () {
      let that = this
      this.clearPositionBool = true
      this.addPositionBool = false
      if (that.source != null) {
        let longitude = document.getElementById(this.str+"-MousePositionLon").value;
        let latitude = document.getElementById(this.str+"-MousePositionLat").value;
        //处理经纬度
        let lonlat = this.getLonLat(longitude,latitude);
        if (lonlat != null) {
          let featureTmp = new Feature({
            geometry: new Point(lonlat)
          });
          let style = that.getPointStyle()
          featureTmp.setStyle(style)
          featureTmp.setProperties({
            type: 'position',
            longitude: longitude,
            latitude: latitude
          })
          that.source.addFeature(featureTmp)
          that.map.getView().setCenter(lonlat)
          that.map.getView().setZoom(12)
        }
      }
    },
    getPointStyle(){// 定位点图标样式
      let style = new Style({
        image: new Icon({
          src: dingweiImg,
          anchor: [0.5, 1]
        }),
      });
      return style;
    },
    getLonLat(longitude, latitude) {
      let lonlat = null
      if (longitude != null && latitude != null & longitude != '' && latitude != '') {
        let lon = Number(longitude)
        let lat = Number(latitude)
        if (lon > 0 && lon < 180 && lat > 0 && lat < 180) {
          lonlat = [ lon, lat]
        }
      }
      return lonlat
    },
    //地图工具箱
    setMapToolBox(value){
      let that = this;
      if (value === 'Clear') {//清空
        //清空
        that.source.clear();
        //停止绘制|修改|拖拽|选择
        clearInteraction();
      }else if (value === 'Point' || value === 'LineString' || value === 'Polygon' || value === 'Circle') {//开启绘制
        //点|线|面|圆绘制
        //开启绘制
        startDrawInteraction(value,false);
      }else if (value === 'FreeHandLineString' || value === 'FreeHandPolygon') {//开启绘制
        //手绘线|手绘面
        value = value.split("FreeHand")[1];
        //开启绘制
        startDrawInteraction(value,true);
      }else if (value === 'StopDraw') {//停止绘制
        //停止绘制
        stopDrawInteraction();
      }else if (value === 'Snap') {//开启捕捉
        //开启捕捉
        startSnapInteraction();
      }else if (value === 'NotSnap') {//停止捕捉
        //停止捕捉
        stopSnapInteraction();
      }else if (value === 'Modify') {//开启修改
        //开启修改
        startModifyInteraction();
      }else if (value === 'NotModify') {//停止修改
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
      }else if (value === 'Drag') {//开启拖拽
        //开启拖拽
        startDragInteraction();
      }else if (value === 'NotDrag') {//停止拖拽
        //停止拖拽
        stopDragInteraction();
      }else if (value === 'Select') {//开启选择
        //开启选择
        startSelectInteraction();
      }else if (value === 'NotSelect') {//停止选择
        //停止选择
        stopSelectInteraction();
      } else if (value === 'MeasureDistance') {//开启测距
        //开启测距
        startMeasureInteraction('LineString');
      } else if (value === 'MeasureArea') {//开启测面
        //开启测面
        startMeasureInteraction('Polygon');
      } else if (value === 'StopMeasure') {//停止测量（测距|测面）
        //停止测量
        stopMeasureInteraction();
      } else if (value === 'ClearMeasure') {//清空测量结果
        //停止测量
        stopMeasureInteraction();
        //清空测量结果
        clearMeasureResult();
      }

      //停止绘制|修改|拖拽|选择
      function clearInteraction() {
        //停止拖拽
        stopDragInteraction();
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
        //停止绘制
        stopDrawInteraction();
      }

      //停止捕捉
      function stopSnapInteraction(){
        if (that.snap) {
          that.map.removeInteraction(that.snap);
          that.snap = null;
        }
      }

      //开启捕捉
      function startSnapInteraction(){
        //停止捕捉
        stopSnapInteraction();
        //开启捕捉
        that.snap = new Snap({
          source: that.source
        });
        that.map.addInteraction(that.snap);
      }

      //停止拖拽
      function stopDragInteraction() {
        //停止拖拽
        if (that.drag) {
          that.map.removeInteraction(that.drag);
          that.drag = null;
        }
      }

      //开启拖拽
      function startDragInteraction() {
        //停止绘制
        stopDrawInteraction();
        //停止修改
        stopModifyInteraction();
        //开启选择
        startSelectInteraction();
        //停止拖拽
        stopDragInteraction();
        //开启拖拽
        that.drag = new Translate({
          features: that.select.getFeatures()
        });
        that.map.addInteraction(that.drag);
      }

      //停止修改
      function stopModifyInteraction() {
        //停止修改
        if (that.modify) {
          that.map.removeInteraction(that.modify);
          that.modify = null;
        }
      }

      //开启修改
      function startModifyInteraction() {
        //停止绘制
        stopDrawInteraction();
        //开启选择
        startSelectInteraction();
        //停止修改
        stopModifyInteraction();
        //开启修改
        // that.modify = new Modify({
        // 	features: that.select.getFeatures()
        // });
        let b = that.map.getInteractions()
        that.modify = new Modify({
          source: that.source
        });
        that.map.addInteraction(that.modify);
      }

      //停止选择
      function stopSelectInteraction() {
        //停止选择
        if (that.select) {
          that.map.removeInteraction(that.select);
          that.select = null;
        }
      }

      //开启选择
      function startSelectInteraction() {
        //停止选择
        stopSelectInteraction();
        //开启选择
        that.select = new Select({
          wrapX: false
        });
        that.map.addInteraction(that.select);
      }

      //停止绘制
      function stopDrawInteraction() {
        //停止绘制
        if (that.draw) {
          that.map.removeInteraction(that.draw);
          that.draw = null;
        }
      }

      //开启绘制
      function startDrawInteraction(type,bool) {
        //停止拖拽
        stopDragInteraction();
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
        //停止绘制
        stopDrawInteraction();
        if(bool){//手绘线|手绘面
          that.draw = new Draw({
            source: that.source,
            type: type,
            snapTolerance: 20,
            freehand: true
          });
          that.map.addInteraction(that.draw);
        }else{//点|线|面|圆绘制
          that.draw = new Draw({
            source: that.source,
            type: type,
            snapTolerance: 20
          });
          that.map.addInteraction(that.draw);
          //绘制结束时触发的事件
          that.draw.on('drawend', function(e) {
            if (e.feature && e.feature.getGeometry() instanceof CircleDraw) {
              let radius = document.getElementById('drawCircleRadius').value
              if (radius != '') {
                radius = radius * 1000
                let metersPerUnit = that.map.getView().getProjection().getMetersPerUnit();
                let circleRadius =  radius / metersPerUnit;
                e.feature.getGeometry().setRadius(circleRadius)
              }
            }
            let geometry = e.feature.getGeometry();
            //停止绘制
            stopDrawInteraction();
            let style
            //设置样式
            if (type == 'Point') {
              style = that.drawPointStyle()
            } else {
              style = that.getPolyonStyle("red");
            }
            e.feature.setStyle(style);
            //计算面积
            if (geometry instanceof Polygon || geometry instanceof CircleDraw) {
              let area = getPolygonArea(geometry);
              //清空查询行政区划列表
              that.parentdistrictList = [];
              //清空区域查询行政区划名称列表
              that.parentdistrictNameList = [];
              //清空区域查询行政区划编码列表
              that.parentdistrictCodeList = [];
              //正在查询
              that.mapLoading("正在查询，请稍候...");
              //新查询绘制区域经纬度任务地区
              that.queryDrawAreaNew(e.feature);
              /*//几何查询--省值
              that.queryProvince(e.feature);
              //几何查询--省会市值
              that.queryProCenCity(e.feature);
              //几何查询--市值
              that.queryCity(e.feature);
              //几何查询--区县值
              that.queryArea(e.feature);
              //获取多边形面内的均匀点分布数组
              let allLonLatArr = that.getPolygonExtentPoints(geometry);
              //查询绘制区域经纬度点地址
              that.queryDrawArea(e.feature,allLonLatArr);*/
              //设置属性
              e.feature.setProperties({area: area});
            }
          });
        }
      }
      //计算面积
      function getPolygonArea (geometry) {
        let area 
        let output
        let circleArea = geometry
        if (geometry instanceof CircleDraw) {
          circleArea = fromCircle(geometry)
        }
        area = getArea(circleArea, {projection: 'EPSG:4490'})
        // 这里一定要给坐标，和地图坐标保持一致，否则面积不准
        output = Math.round((area / 1000000) * 100) / 100;//平方公里
        return output;
      }

      ////////////////////////////////////////////////////////////////////测量工具箱
      //格式化距离
      function formatLength(line) {
        const length = getLength(line, {projection: 'EPSG:4490'});
        let output;
        if (length > 100) {
          output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km';
        } else {
          output = Math.round(length * 100) / 100 + ' ' + 'm';
        }
        return output;
      }

      //格式化面积
      function formatArea(polygon) {
        const area = getArea(polygon, {projection: 'EPSG:4490'});
        let output;
        if (area > 10000) {
          output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km<sup>2</sup>';
        } else {
          output = Math.round(area * 100) / 100 + ' ' + 'm<sup>2</sup>';
        }
        return output;
      }

      //创建新的提示tip
      function createHelpTooltip() {
        if (that.helpTooltipElement!=null) {
          that.helpTooltipElement.parentNode.removeChild(that.helpTooltipElement);
        }
        that.helpTooltipElement = document.createElement('div');
        that.helpTooltipElement.className = 'ol-tooltip hidden';
        that.helpTooltip = new Overlay({
          element: that.helpTooltipElement,
          offset: [15, 0],
          positioning: 'center-left',
        });
        that.map.addOverlay(that.helpTooltip);
      }

      //创建新的测量提示
      function createMeasureTooltip() {
        if (that.measureTooltipElement!=null) {
          that.measureTooltipElement.parentNode.removeChild(that.measureTooltipElement);
        }
        that.measureTooltipElement = document.createElement('div');
        that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure';
        that.measureTooltip = new Overlay({
          element: that.measureTooltipElement,
          offset: [0, -15],
          positioning: 'bottom-center',
          stopEvent: false,
          insertFirst: false,
        });
        that.map.addOverlay(that.measureTooltip);
      }
      //开启测量工具
      function startMeasureInteraction(type) {
        //停止测量工具
        stopMeasureInteraction();

        console.log(type);
        //开启测量工具--绘制
        that.measure = new Draw({
          source: that.measureSource,
          type: type,
          style: new Style({
            fill: new Fill({
              color: 'rgba(255, 255, 255, 0.2)',
            }),
            stroke: new Stroke({
              color: 'rgba(0, 0, 0, 0.5)',
              lineDash: [10, 10],
              width: 2,
            }),
            image: new CircleStyle({
              radius: 5,
              stroke: new Stroke({
                color: 'rgba(0, 0, 0, 0.7)',
              }),
              fill: new Fill({
                color: 'rgba(255, 255, 255, 0.2)',
              }),
            }),
          }),
        });
        that.map.addInteraction(that.measure);

        //创建新的测量提示
        createMeasureTooltip();
        //创建新的提示tip
        createHelpTooltip();

        let listener;
        that.measure.on('drawstart', function (evt) {
          //设置sketch
          that.sketch = evt.feature;

          let tooltipCoord = evt.coordinate;

          listener = that.sketch.getGeometry().on('change', function (evt) {
            const geom = evt.target;
            let output;
            if (geom instanceof Polygon) {
              output = formatArea(geom);
              tooltipCoord = geom.getInteriorPoint().getCoordinates();
            } else if (geom instanceof LineString) {
              output = formatLength(geom);
              tooltipCoord = geom.getLastCoordinate();
            }
            that.measureTooltipElement.innerHTML = output;
            that.measureTooltip.setPosition(tooltipCoord);
          });
        });
        //完成测量绘制
        that.measure.on('drawend', function () {
          that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static';
          that.measureTooltip.setOffset([0, -7]);
          //添加到数组
          that.measureTooltipArray.push(that.helpTooltip);
          //添加到数组
          that.measureTooltipArray.push(that.measureTooltip);
          //清空sketch
          that.sketch = null;
          //清空tooltip
          that.measureTooltipElement = null;
          createMeasureTooltip();
          unByKey(listener);
        });
      }

      //停止测量工具
      function stopMeasureInteraction() {
        //停止绘制
        stopDrawInteraction();
        //停止测量工具
        if (that.measure) {
          that.map.removeInteraction(that.measure);
          that.measure = null;
          //隐藏提示tip
          that.helpTooltipElement.classList.add('hidden');
          //移除测量提示
          if(that.helpTooltip!=null){
            that.map.removeOverlay(that.helpTooltip);
          }
          if(that.measureTooltip!=null){
            that.map.removeOverlay(that.measureTooltip);
          }
        }
      }
      
      //清空测量结果
      function clearMeasureResult(){
        if(that.measureSource!=null){
          //清空测量结果
          that.measureSource.clear();
          //清空测量结果提示数组
          if(that.measureTooltipArray.length>0){
            for(let i=0;i<that.measureTooltipArray.length;i++){
              that.map.removeOverlay(that.measureTooltipArray[i]);
            }
            that.measureTooltipArray = [];
          }
        }
      }
    },
    autodivheight() {//自动获取div高度
      //获取浏览器窗口高度
      let winHeight = 0;
      if (window.innerHeight) {
        winHeight = window.innerHeight;
      } else if ((document.body) && (document.body.clientHeight)) {
        winHeight = document.body.clientHeight;
      }
      //通过深入Document内部对body进行检测，获取浏览器窗口高度
      if (document.documentElement && document.documentElement.clientHeight) {
        winHeight = document.documentElement.clientHeight;
      }
      //全屏时窗口高度:864px,地图div高度:754px
      let tempHeight = 864;
      let mapTempHeight = 754;
      let mapHeight = winHeight - tempHeight + mapTempHeight;
      //最小高度
      if(mapHeight<480){
        mapHeight = 480;
      }
      //设置地图高度
      document.getElementById(this.str+"-map").style.height= mapHeight +"px";
      console.log("窗口高度："+winHeight+"地图高度："+mapHeight);
      //resize事件--刷新地图,确保地图不变形
      if(this.map){
        this.map.updateSize();
        console.log("resize事件--刷新地图,确保地图不变形");
      }
    },
    //设施网络查询图层
    addNetworkAnalystLayer(bool,queryId) {
      if(this.networkFeatureLayer!=null && bool==true){
        this.networkFeatureLayer.getSource().clear();
      }
      let networkType = document.getElementById(this.str + '-networkType').value;//POINT、LINE
      if(bool) {
        queryId = document.getElementById(this.str + '-networkId').value;
      }
      let sqlFilter = "SMID = "+ queryId;
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/map-changchun/rest/maps/长春市区图";
      // let datasource = "dxPipeNetwork";
      // let dataset = "dxPipeNetwork_Network";
      let datasource = this.networkDatasource;
      let dataset = this.networkDataset;
      //test
      // that.networkUrl = "http://10.7.208.233:8080/iserver/services/transportationAnalyst-dxPipeNetwork/rest/networkanalyst/dxPipeNetwork_Network@dxPipeNetwork";//网络分析服务url
      // that.networkDatasource = "dxPipeNetwork";//网络分析数据源
      // that.networkDataset = "dxPipeNetwork_Network";//网络分析数据集
      // that.networkUrl = "http://10.7.208.233:8080/iserver/services/map-dxPipeNetwork/rest/maps/dxPipeNetwork_Network@dxPipeNetwork";//网络分析地图服务url
      //test
      // that.networkUrl = "http://10.13.155.192:8090/iserver/services/transportationAnalyst-smxNetwork/rest/networkanalyst/DataSource_Network@DataSource";//网络分析服务url
      // that.networkDatasource = "DataSource";//网络分析数据源
      // that.networkDataset = "DataSource_Network";//网络分析数据集
      // that.networkMapUrl = "http://10.13.155.192:8090/iserver/services/map-smxNetwork/rest/maps/DataSource_Network@DataSource";//网络分析地图服务url
      let layerUrl = this.networkMapUrl;//网络分析地图服务url
      // SQL查询超图图层数据
      mapSqlQueryResultsPost({layerUrl:layerUrl,datasource:datasource,dataset:dataset,networkType:networkType,sqlFilter:sqlFilter}).then(res => {
        if (res.code == 200) {
          let result = res.data;
          let currentCount = result.currentCount;
          let totalCount = result.totalCount;
          let recordsets = result.recordsets;
          let features = recordsets[0].features;
          if(features.length>0){
            //全部经纬度
            let allCoordinates = [];
            for(let i=0;i<features.length;i++){
              let id = features[i].ID;
              let fieldNames = features[i].fieldNames;
              let fieldValues = features[i].fieldValues;
              let geometry = features[i].geometry;
              let type = geometry.type;
              if(type=="POINT" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "POINT(";
                if(points.length==1){
                  let tempPoint = points[0];
                  let lon = tempPoint.x;
                  let lat = tempPoint.y;
                  let lonlat = [lon,lat];
                  wkt += lonlat[0] + " " + lonlat[1];
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  image: new CircleStyle({
                    radius: 5,
                    fill: new Fill({
                      color: "red",
                    }),
                  }),
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkFeatureLayer.getSource().addFeature(featureTmp);
                //获取范围
                let extent = featureTmp.getGeometry().getExtent();
                if(extent.length==4){
                  //全部经纬度--左下角
                  allCoordinates.push([extent[0],extent[1]]);
                  //全部经纬度--右上角
                  allCoordinates.push([extent[2],extent[3]]);
                }
              }else if(type=="LINE" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "LINESTRING(";
                if(points.length>0){
                  for(let j=0;j<points.length;j++){
                    let tempPoint = points[j];
                    let lon = tempPoint.x;
                    let lat = tempPoint.y;
                    let lonlat = [lon,lat];
                    wkt += lonlat[0] + " " + lonlat[1] + ",";
                  }
                  wkt = wkt.substring(0,wkt.length-1);
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  stroke: new Stroke({
                    color: 'red',
                    width: 5
                  })
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkFeatureLayer.getSource().addFeature(featureTmp);
                //获取范围
                let extent = featureTmp.getGeometry().getExtent();
                if(extent.length==4){
                  //全部经纬度--左下角
                  allCoordinates.push([extent[0],extent[1]]);
                  //全部经纬度--右上角
                  allCoordinates.push([extent[2],extent[3]]);
                }
              }
            }
            let extent = boundingExtent(allCoordinates);
            this.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
          }
        }
      })
    },
    //查询设施网络源点ID数组字符串
    queryNetworkSourceNodeIDs() {
      this.sourceNodeIDsArray = [];
      this.sourceNodeIDs = "";
      if(this.networkFeatureLayer!=null){
        this.networkFeatureLayer.getSource().clear();
      }
      let networkType = "POINT";
      let sqlFilter = "NODETYPE = 1";//1源点
      // let datasource = "dxPipeNetwork";
      // let dataset = "dxPipeNetwork_Network";
      let datasource = this.networkDatasource;
      let dataset = this.networkDataset;
      //test
      // that.networkUrl = "http://10.7.208.233:8080/iserver/services/transportationAnalyst-dxPipeNetwork/rest/networkanalyst/dxPipeNetwork_Network@dxPipeNetwork";//网络分析服务url
      // that.networkDatasource = "dxPipeNetwork";//网络分析数据源
      // that.networkDataset = "dxPipeNetwork_Network";//网络分析数据集
      // that.networkUrl = "http://10.7.208.233:8080/iserver/services/map-dxPipeNetwork/rest/maps/dxPipeNetwork_Network@dxPipeNetwork";//网络分析地图服务url
      //test
      // that.networkUrl = "http://10.13.155.192:8090/iserver/services/transportationAnalyst-smxNetwork/rest/networkanalyst/DataSource_Network@DataSource";//网络分析服务url
      // that.networkDatasource = "DataSource";//网络分析数据源
      // that.networkDataset = "DataSource_Network";//网络分析数据集
      // that.networkMapUrl = "http://10.13.155.192:8090/iserver/services/map-smxNetwork/rest/maps/DataSource_Network@DataSource";//网络分析地图服务url
      let layerUrl = this.networkMapUrl;//网络分析地图服务url
      // SQL查询超图图层数据
      mapSqlQueryResultsPost({layerUrl:layerUrl,datasource:datasource,dataset:dataset,networkType:networkType,sqlFilter:sqlFilter}).then(res => {
        if (res.code == 200) {
          let result = res.data;
          let currentCount = result.currentCount;
          let totalCount = result.totalCount;
          let recordsets = result.recordsets;
          let features = recordsets[0].features;
          if(features.length>0){
            let sourceNodeIDs = "[";
            for(let i=0;i<features.length;i++){
              let id = features[i].ID;
              this.sourceNodeIDsArray.push(id);
              sourceNodeIDs += id + ",";
              let fieldNames = features[i].fieldNames;
              let fieldValues = features[i].fieldValues;
              let geometry = features[i].geometry;
              let type = geometry.type;
              if(type=="POINT" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "POINT(";
                if(points.length==1){
                  let tempPoint = points[0];
                  let lon = tempPoint.x;
                  let lat = tempPoint.y;
                  let lonlat = [lon,lat];
                  wkt += lonlat[0] + " " + lonlat[1];
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  image: new CircleStyle({
                    radius: 5,
                    fill: new Fill({
                      color: "purple",
                    }),
                  }),
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkFeatureLayer.getSource().addFeature(featureTmp);
              }
            }
            sourceNodeIDs = sourceNodeIDs.substring(0,sourceNodeIDs.length-1);
            sourceNodeIDs += "]";
            this.sourceNodeIDs = sourceNodeIDs;
          }
        }
      })
    },
    setNetworkNotValidId(){//设置无效节点或弧段
      // this.notValidNetworkNodeIdArray = [];//无效节点ID
      // this.notValidNetworkEdgeIdArray = [];//无效弧段ID
      let notValidNetworkId = document.getElementById(this.str + '-notValidNetworkId').value;
      let networkType = document.getElementById(this.str + '-networkType').value;//POINT、LINE
      if(networkType=="POINT"){
        // this.notValidNetworkNodeIdArray = [notValidNetworkId];//无效节点ID
        this.notValidNetworkNodeIdArray.push(notValidNetworkId);//无效节点ID
      }else if(networkType=="LINE"){
        // this.notValidNetworkEdgeIdArray = [notValidNetworkId];//无效弧段ID
        this.notValidNetworkEdgeIdArray.push(notValidNetworkId);//无效弧段ID
      }
    },
    traceDownAnalyst(bool,queryId) {//下游追踪
      if(this.networkAnalystLayer!=null && bool==true){
        this.networkAnalystLayer.getSource().clear();
      }
      if(bool){
        queryId = document.getElementById(this.str + '-networkId').value;
        this.tempNetworkNodeIdArray = [];
        this.tempNetworkEdgeIdArray = [];
        this.featureNetworkNodeIdArray = [];//查询结果绘制节点ID
        this.featureNetworkEdgeIdArray = [];//查询结果绘制弧段ID
      }
      let networkType = document.getElementById(this.str + '-networkType').value;//POINT、LINE
      let nodeID = null;
      let edgeID = null;
      if(networkType=="POINT"){
        nodeID = queryId;
        //判断节点是否已进行过下游追踪分析
        let bool = this.checkArrayHasItem(this.tempNetworkNodeIdArray,queryId);//校验数组是否已包含数据
        if(bool){//节点是否无效或已进行过下游追踪分析
          return;
        }
        //判断节点是否无效
        let bool0 = this.checkArrayHasItem(this.notValidNetworkNodeIdArray,queryId);//校验数组是否已包含数据
        if(bool0){
          console.log("无效节点ID:"+queryId);
          return;
        }
        console.log(queryId + "---节点下游追踪分析");
        this.tempNetworkNodeIdArray.push(queryId);
      }else if(networkType=="LINE"){
        edgeID = queryId;
        //判断弧段是否已进行过下游追踪分析
        let bool = this.checkArrayHasItem(this.tempNetworkEdgeIdArray,queryId);//校验数组是否已包含数据
        if(bool){//弧段是否无效或已进行过下游追踪分析
          return;
        }
        //判断弧段是否无效
        let bool0 = this.checkArrayHasItem(this.notValidNetworkEdgeIdArray,queryId);//校验数组是否已包含数据
        if(bool0){
          console.log("无效弧段ID:"+queryId);
          return;
        }
        console.log(queryId + "---弧段下游追踪分析");
        this.tempNetworkEdgeIdArray.push(queryId);
      }
      console.log(bool+"下游追踪"+queryId);
      // this.addNetworkAnalystLayer(false,queryId);
      this.traceDownAnalystProcess(networkType,queryId,nodeID,edgeID);//下游追踪
    },
    traceDownAnalystProcess(networkType,queryId,nodeID,edgeID) {//下游追踪
      let returnFeatures = true;
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/map-changchun/rest/maps/长春市区图";
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/transportationAnalyst-dxPipeNetwork/rest/networkanalyst/dxPipeNetwork_Network@dxPipeNetwork";
      let layerUrl = this.networkUrl;
      // 下游追踪
      networkTracedown({layerUrl:layerUrl,nodeID:nodeID,edgeID:edgeID,isUncertainDirectionValid:true,returnFeatures:returnFeatures}).then(res => {
        if (res.code == 200) {
          let result = res.data;
          let nodes = result.nodes;
          let nodesFeatures = result.nodesFeatures;
          let edges = result.edges;
          let edgesFeatures = result.edgesFeatures;
          if((nodes==null || nodes.length==0) && (edges==null || edges.length==0)){
            ElMessage.warning("无查询结果");
            return;
          }
          /*if(networkType=="POINT"){
            for(let i=0;i<nodes.length;i++){
              if(nodes[i]!=queryId){
                this.traceDownAnalyst(false,nodes[i]);//节点下游追踪
              }
            }
          }else if(networkType=="LINE"){
            for(let i=0;i<edges.length;i++){
              if(edges[i]!=queryId){
                this.traceDownAnalyst(false,nodes[i]);//弧段下游追踪
              }
            }
          }*/
          //弧段
          if(returnFeatures && edgesFeatures.length>0){
            for(let i=0;i<edgesFeatures.length;i++){
              if(edgesFeatures[i]==null){
                continue;
              }
              let id = edgesFeatures[i].ID;
              //是否已有查询结果绘制弧段ID
              let bool1 = this.checkArrayHasItem(this.featureNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(bool1){
                continue;
              }
              this.featureNetworkEdgeIdArray.push(id);
              //判断弧段是否无效
              let edgeBool = this.checkArrayHasItem(this.notValidNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(edgeBool){
                break;
              }
              let fieldNames = edgesFeatures[i].fieldNames;
              let fieldValues = edgesFeatures[i].fieldValues;
              let geometry = edgesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="LINE" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "LINESTRING(";
                if(points.length>0){
                  for(let j=0;j<points.length;j++){
                    let tempPoint = points[j];
                    let lon = tempPoint.x;
                    let lat = tempPoint.y;
                    let lonlat = [lon,lat];
                    wkt += lonlat[0] + " " + lonlat[1] + ",";
                  }
                  wkt = wkt.substring(0,wkt.length-1);
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  stroke: new Stroke({
                    color: 'blue',
                    width: 5
                  })
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
          //节点
          if(returnFeatures && nodesFeatures.length>0){
            for(let i=0;i<nodesFeatures.length;i++){
              if(nodesFeatures[i]==null){
                continue;
              }
              let id = nodesFeatures[i].ID;
              //是否已有查询结果绘制节点ID
              let bool2 = this.checkArrayHasItem(this.featureNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(bool2){
                continue;
              }
              this.featureNetworkNodeIdArray.push(id);
              //判断节点是否无效
              let nodeBool = this.checkArrayHasItem(this.notValidNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(nodeBool){
                console.log("无效nodeID:"+id);
                break;
              }
              let fieldNames = nodesFeatures[i].fieldNames;
              let fieldValues = nodesFeatures[i].fieldValues;
              let geometry = nodesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="POINT" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "POINT(";
                if(points.length==1){
                  let tempPoint = points[0];
                  let lon = tempPoint.x;
                  let lat = tempPoint.y;
                  let lonlat = [lon,lat];
                  wkt += lonlat[0] + " " + lonlat[1];
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  image: new CircleStyle({
                    radius: 5,
                    fill: new Fill({
                      color: "green",
                    }),
                  }),
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
        }
      });
    },
    checkArrayHasItem(array,item){//校验数组是否已包含数据
      let bool = false;
      if(array!=null && array.length>0){
        for(let i=0;i<array.length;i++){
          if(array[i]==item){
            bool = true;
            break;
          }
        }
      }

      return bool;
    },
    networkToolBox() {//超图设施网络分析工具
      if(this.networkUrl){
        if (this.showHideNetworkTool) {
          this.showHideNetworkTool = false
          document.getElementById(this.str + '-NetworkDiv').style.display = 'block';
          //添加网络分析地图服务图层
          getNetworkLayer(this.map,this.networkMapUrl);
          //查询源点
          this.queryNetworkSourceNodeIDs();
        } else {
          this.showHideNetworkTool = true
          document.getElementById(this.str + '-NetworkDiv').style.display = 'none'
        }
      }else{
        ElMessage.warning("无网络拓扑数据！");
      }
    },
    traceUpAnalyst(bool,queryId) {//上游追踪
      if(this.networkAnalystLayer!=null && bool==true){
        this.networkAnalystLayer.getSource().clear();
      }
      if(bool){
        queryId = document.getElementById(this.str + '-networkId').value;
        this.tempNetworkNodeIdArray = [];
        this.tempNetworkEdgeIdArray = [];
        this.featureNetworkNodeIdArray = [];//查询结果绘制节点ID
        this.featureNetworkEdgeIdArray = [];//查询结果绘制弧段ID
      }
      let networkType = document.getElementById(this.str + '-networkType').value;//POINT、LINE
      let nodeID = null;
      let edgeID = null;
      if(networkType=="POINT"){
        nodeID = queryId;
        //判断节点是否已进行过上游追踪分析
        let bool = this.checkArrayHasItem(this.tempNetworkNodeIdArray,queryId);//校验数组是否已包含数据
        if(bool){//节点是否无效或已进行过上游追踪分析
          return;
        }
        //判断节点是否无效
        let bool0 = this.checkArrayHasItem(this.notValidNetworkNodeIdArray,queryId);//校验数组是否已包含数据
        if(bool0){
          console.log("无效节点ID:"+queryId);
          return;
        }
        console.log(queryId + "---节点上游追踪分析");
        this.tempNetworkNodeIdArray.push(queryId);
      }else if(networkType=="LINE"){
        edgeID = queryId;
        //判断弧段是否无效
        let bool0 = this.checkArrayHasItem(this.notValidNetworkEdgeIdArray,queryId);//校验数组是否已包含数据
        //判断弧段是否已进行过上游追踪分析
        let bool = this.checkArrayHasItem(this.tempNetworkEdgeIdArray,queryId);//校验数组是否已包含数据
        if(bool0 || bool){//弧段是否无效或已进行过上游追踪分析
          return;
        }
        console.log(queryId + "---弧段上游追踪分析");
        this.tempNetworkEdgeIdArray.push(queryId);
      }
      console.log(bool+"上游追踪"+queryId);
      // this.addNetworkAnalystLayer(false,queryId);
      this.traceUpAnalystProcess(networkType,queryId,nodeID,edgeID);//上游追踪
    },
    traceUpAnalystProcess(networkType,queryId,nodeID,edgeID) {//上游追踪
      let returnFeatures = true;
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/map-changchun/rest/maps/长春市区图";
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/transportationAnalyst-dxPipeNetwork/rest/networkanalyst/dxPipeNetwork_Network@dxPipeNetwork";
      let layerUrl = this.networkUrl;
      // 上游追踪
      networkTraceup({layerUrl:layerUrl,nodeID:nodeID,edgeID:edgeID,isUncertainDirectionValid:true,returnFeatures:returnFeatures}).then(res => {
        if (res.code == 200) {
          let result = res.data;
          let nodes = result.nodes;
          let nodesFeatures = result.nodesFeatures;
          let edges = result.edges;
          let edgesFeatures = result.edgesFeatures;
          if((nodes==null || nodes.length==0) && (edges==null || edges.length==0)){
            ElMessage.warning("无查询结果");
            return;
          }
          /*if(networkType=="POINT"){
            for(let i=0;i<nodes.length;i++){
              if(nodes[i]!=queryId){
                this.traceUpAnalyst(false,nodes[i]);//节点上游追踪
              }
            }
          }else if(networkType=="LINE"){
            for(let i=0;i<edges.length;i++){
              if(edges[i]!=queryId){
                this.traceUpAnalyst(false,nodes[i]);//弧段上游追踪
              }
            }
          }*/
          //弧段
          if(returnFeatures && edgesFeatures.length>0){
            for(let i=0;i<edgesFeatures.length;i++){
              if(edgesFeatures[i]==null){
                continue;
              }
              let id = edgesFeatures[i].ID;
              //是否已有查询结果绘制弧段ID
              let bool1 = this.checkArrayHasItem(this.featureNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(bool1){
                continue;
              }
              this.featureNetworkEdgeIdArray.push(id);
              //判断弧段是否无效
              let edgeBool = this.checkArrayHasItem(this.notValidNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(edgeBool){
                break;
              }
              let fieldNames = edgesFeatures[i].fieldNames;
              let fieldValues = edgesFeatures[i].fieldValues;
              let geometry = edgesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="LINE" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "LINESTRING(";
                if(points.length>0){
                  for(let j=0;j<points.length;j++){
                    let tempPoint = points[j];
                    let lon = tempPoint.x;
                    let lat = tempPoint.y;
                    let lonlat = [lon,lat];
                    wkt += lonlat[0] + " " + lonlat[1] + ",";
                  }
                  wkt = wkt.substring(0,wkt.length-1);
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  stroke: new Stroke({
                    color: 'blue',
                    width: 5
                  })
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
          //节点
          if(returnFeatures && nodesFeatures.length>0){
            for(let i=0;i<nodesFeatures.length;i++){
              if(nodesFeatures[i]==null){
                continue;
              }
              let id = nodesFeatures[i].ID;
              //是否已有查询结果绘制节点ID
              let bool2 = this.checkArrayHasItem(this.featureNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(bool2){
                continue;
              }
              this.featureNetworkNodeIdArray.push(id);
              //判断节点是否无效
              let nodeBool = this.checkArrayHasItem(this.notValidNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(nodeBool){
                console.log("无效nodeID:"+id);
                break;
              }
              let fieldNames = nodesFeatures[i].fieldNames;
              let fieldValues = nodesFeatures[i].fieldValues;
              let geometry = nodesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="POINT" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "POINT(";
                if(points.length==1){
                  let tempPoint = points[0];
                  let lon = tempPoint.x;
                  let lat = tempPoint.y;
                  let lonlat = [lon,lat];
                  wkt += lonlat[0] + " " + lonlat[1];
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  image: new CircleStyle({
                    radius: 5,
                    fill: new Fill({
                      color: "green",
                    }),
                  }),
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
        }
      });
    },
    burstAnalyse(){//爆管分析
      this.sourceNodeIDs = "[6]";
      if(this.networkAnalystLayer!=null){
        this.networkAnalystLayer.getSource().clear();
      }
      this.featureNetworkNodeIdArray = [];//查询结果绘制节点ID
      this.featureNetworkEdgeIdArray = [];//查询结果绘制弧段ID
      let networkType = document.getElementById(this.str + '-networkType').value;//POINT、LINE
      let queryId = document.getElementById(this.str + '-networkId').value;
      let nodeID = null;
      let edgeID = null;
      if(networkType=="POINT"){
        nodeID = queryId;
        console.log(queryId + "---节点爆管分析");
      }else if(networkType=="LINE"){
        edgeID = queryId;
        console.log(queryId + "---弧段爆管分析");
      }
      // let sourceNodeIDs = "[6,30]";//设施点
      let sourceNodeIDs = this.sourceNodeIDs;//设施点
      // this.addNetworkAnalystLayer(false,queryId);
      let returnFeatures = true;
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/map-changchun/rest/maps/长春市区图";
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/transportationAnalyst-dxPipeNetwork/rest/networkanalyst/dxPipeNetwork_Network@dxPipeNetwork";
      let layerUrl = this.networkUrl;
      // 爆管分析
      networkBurstanalyse({layerUrl:layerUrl,sourceNodeIDs:sourceNodeIDs,nodeID:nodeID,edgeID:edgeID,isUncertainDirectionValid:true,returnFeatures:true}).then(res => {
        if (res.code == 200) {
          let result = res.data;
          let criticalNodes = result.criticalNodes;//爆管分析中影响爆管位置上下游的关键设施点
          let criticalNodesFeatures = result.criticalNodesFeatures;
          let normalNodes = result.normalNodes;//爆管分析中受爆管位置影响的普通设施点
          let normalNodesFeatures = result.normalNodesFeatures;
          let edges = result.edges;//上下游中影响爆管位置的弧段和受爆管位置影响的弧段
          let edgesFeatures = result.edgesFeatures;
          if((criticalNodes==null || criticalNodes.length==0) && (normalNodes==null || normalNodes.length==0) && (edges==null || edges.length==0)){
            ElMessage.warning("无查询结果");
            return;
          }
          //弧段
          if(edgesFeatures.length>0){
            for(let i=0;i<edgesFeatures.length;i++){
              if(edgesFeatures[i]==null){
                continue;
              }
              let id = edgesFeatures[i].ID;
              //是否已有查询结果绘制弧段ID
              let bool1 = this.checkArrayHasItem(this.featureNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(bool1){
                continue;
              }
              this.featureNetworkEdgeIdArray.push(id);
              //判断弧段是否无效
              let edgeBool = this.checkArrayHasItem(this.notValidNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(edgeBool){
                break;
              }
              let fieldNames = edgesFeatures[i].fieldNames;
              let fieldValues = edgesFeatures[i].fieldValues;
              let geometry = edgesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="LINE" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "LINESTRING(";
                if(points.length>0){
                  for(let j=0;j<points.length;j++){
                    let tempPoint = points[j];
                    let lon = tempPoint.x;
                    let lat = tempPoint.y;
                    let lonlat = [lon,lat];
                    wkt += lonlat[0] + " " + lonlat[1] + ",";
                  }
                  wkt = wkt.substring(0,wkt.length-1);
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  stroke: new Stroke({
                    color: 'blue',
                    width: 5
                  })
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
          //普通设施点
          if(normalNodesFeatures.length>0){
            for(let i=0;i<normalNodesFeatures.length;i++){
              if(normalNodesFeatures[i]==null){
                continue;
              }
              let id = normalNodesFeatures[i].ID;
              //是否已有查询结果绘制节点ID
              let bool2 = this.checkArrayHasItem(this.featureNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(bool2){
                continue;
              }
              this.featureNetworkNodeIdArray.push(id);
              //判断节点是否无效
              let nodeBool = this.checkArrayHasItem(this.notValidNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(nodeBool){
                break;
              }
              let fieldNames = normalNodesFeatures[i].fieldNames;
              let fieldValues = normalNodesFeatures[i].fieldValues;
              let geometry = normalNodesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="POINT" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "POINT(";
                if(points.length==1){
                  let tempPoint = points[0];
                  let lon = tempPoint.x;
                  let lat = tempPoint.y;
                  let lonlat = [lon,lat];
                  wkt += lonlat[0] + " " + lonlat[1];
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  image: new CircleStyle({
                    radius: 5,
                    fill: new Fill({
                      color: "green",
                    }),
                  }),
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
          //关键设施点
          if(criticalNodesFeatures.length>0){
            for(let i=0;i<criticalNodesFeatures.length;i++){
              if(criticalNodesFeatures[i]==null){
                continue;
              }
              let id = criticalNodesFeatures[i].ID;
              //是否已有查询结果绘制节点ID
              let bool2 = this.checkArrayHasItem(this.featureNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(bool2){
                continue;
              }
              this.featureNetworkNodeIdArray.push(id);
              //判断节点是否无效
              let nodeBool = this.checkArrayHasItem(this.notValidNetworkNodeIdArray,id);//校验数组是否已包含数据
              if(nodeBool){
                break;
              }
              let fieldNames = criticalNodesFeatures[i].fieldNames;
              let fieldValues = criticalNodesFeatures[i].fieldValues;
              let geometry = criticalNodesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="POINT" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "POINT(";
                if(points.length==1){
                  let tempPoint = points[0];
                  let lon = tempPoint.x;
                  let lat = tempPoint.y;
                  let lonlat = [lon,lat];
                  wkt += lonlat[0] + " " + lonlat[1];
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  image: new CircleStyle({
                    radius: 5,
                    fill: new Fill({
                      color: "orange",
                    }),
                  }),
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
        }
      });
    },
    networkConnectededgesAnalyst(){//连通性分析
      if(this.networkAnalystLayer!=null){
        this.networkAnalystLayer.getSource().clear();
      }
      this.featureNetworkNodeIdArray = [];//查询结果绘制节点ID
      this.featureNetworkEdgeIdArray = [];//查询结果绘制弧段ID
      let networkType = document.getElementById(this.str + '-networkType').value;//POINT、LINE
      let queryId = document.getElementById(this.str + '-networkId').value;
      let nodeIDs = null;
      let edgeIDs = null;
      if(networkType=="POINT"){
        nodeIDs = "["+queryId+"]";
        console.log(queryId + "---节点连通性分析");
      }else if(networkType=="LINE"){
        edgeIDs = "["+queryId+"]";
        console.log(queryId + "---弧段连通性分析");
      }
      // let sourceNodeIDs = "[6,30]";//设施点
      let sourceNodeIDs = this.sourceNodeIDs;//设施点
      // this.addNetworkAnalystLayer(false,queryId);
      let returnFeatures = true;
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/map-changchun/rest/maps/长春市区图";
      // let layerUrl = "http://10.7.208.233:8080/iserver/services/transportationAnalyst-dxPipeNetwork/rest/networkanalyst/dxPipeNetwork_Network@dxPipeNetwork";
      let layerUrl = this.networkUrl;
      // 连通性分析
      networkConnectededges({layerUrl:layerUrl,nodeIDs:nodeIDs,edgeIDs:edgeIDs,connected:true,returnFeatures:returnFeatures}).then(res => {
        if (res.code == 200) {
          let result = res.data;
          // let nodes = result.nodes;
          // let nodesFeatures = result.nodesFeatures;
          let edges = result.edges;
          let edgesFeatures = result.edgesFeatures;
          if(edges==null || edges.length==0){
            ElMessage.warning("无查询结果");
            return;
          }
          //弧段
          if(returnFeatures && edgesFeatures.length>0){
            for(let i=0;i<edgesFeatures.length;i++){
              if(edgesFeatures[i]==null){
                continue;
              }
              let id = edgesFeatures[i].ID;
              //是否已有查询结果绘制弧段ID
              let bool1 = this.checkArrayHasItem(this.featureNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(bool1){
                continue;
              }
              this.featureNetworkEdgeIdArray.push(id);
              //判断弧段是否无效
              let edgeBool = this.checkArrayHasItem(this.notValidNetworkEdgeIdArray,id);//校验数组是否已包含数据
              if(edgeBool){
                break;
              }
              let fieldNames = edgesFeatures[i].fieldNames;
              let fieldValues = edgesFeatures[i].fieldValues;
              let geometry = edgesFeatures[i].geometry;
              let type = geometry.type;
              if(type=="LINE" && geometry!=null){
                let parts = geometry.parts;
                let points = geometry.points;
                let wkt = "LINESTRING(";
                if(points.length>0){
                  for(let j=0;j<points.length;j++){
                    let tempPoint = points[j];
                    let lon = tempPoint.x;
                    let lat = tempPoint.y;
                    let lonlat = [lon,lat];
                    wkt += lonlat[0] + " " + lonlat[1] + ",";
                  }
                  wkt = wkt.substring(0,wkt.length-1);
                }else{
                  continue;
                }
                wkt += ")";
                // console.log(wkt);
                //空间数据
                let featureTmp = new WKT().readFeature(wkt);
                //设置属性
                featureTmp.setProperties({
                  type:"networkResult",//类型
                  geometryType:type,
                  fieldNames:fieldNames,
                  fieldValues:fieldValues
                });
                let style = new Style({
                  stroke: new Stroke({
                    color: 'blue',
                    width: 5
                  })
                });
                featureTmp.setStyle(style);
                //添加矢量数据
                this.networkAnalystLayer.getSource().addFeature(featureTmp);
              }
            }
          }
          //计算连通性从源点的连接顺序网络ID数组
          if(this.sourceNodeIDsArray.length>0){
            for(let i=0;i<this.sourceNodeIDsArray.length;i++){
              let sourceNodeID = this.sourceNodeIDsArray[i];
              //弧段
              if(returnFeatures && edgesFeatures.length>0 && sourceNodeID==queryId) {
                let allEdgeIdObjArray = [];
                let isVaild = true;//是否有效
                //根据节点ID和已获取的弧段ID继续遍历连通性的弧段数组并获取新的弧段ID
                allEdgeIdObjArray = this.checkEdgesFeatures(edgesFeatures,sourceNodeID,allEdgeIdObjArray,isVaild);
                console.log("allEdgeIdObjArray");
                console.log(allEdgeIdObjArray);
                break;
              }
            }
          }
        }
      });
    },
    //根据节点ID和已获取的弧段ID继续遍历连通性的弧段数组并获取新的弧段ID
    checkEdgesFeatures(edgesFeatures,nodeId,allEdgeIdObjArray,isVaild){
      let that = this;
      let edgeIdObjArray = [];
      if(edgesFeatures!=null && edgesFeatures.length>0){
        for(let i=0;i<edgesFeatures.length;i++){
          let ID = edgesFeatures[i].ID;
          let fieldNames = edgesFeatures[i].fieldNames;
          let fieldValues = edgesFeatures[i].fieldValues;
          let geometry = edgesFeatures[i].geometry;
          let type = geometry.type;
          let smFNode = edgesFeatures[i].fieldValues[4];
          let smTNode = edgesFeatures[i].fieldValues[5];
          let smEdgeID = edgesFeatures[i].fieldValues[6];
          let nextNodeId = null;
          let edgeBool = false;
          if(smFNode==nodeId || smTNode==nodeId){
            if(smFNode==nodeId){
              nodeId = smFNode;
              nextNodeId = smTNode;
            }else if(smTNode==nodeId){
              nodeId = smTNode;
              nextNodeId = smFNode;
            }
            let tempVaildBool = true;
            if(isVaild){
              //判断是否无效的节点
              if(this.notValidNetworkNodeIdArray.indexOf(nodeId)!=-1){
                tempVaildBool = false;
              }
              //判断是否无效的弧段
              if(this.notValidNetworkEdgeIdArray.indexOf(smEdgeID)!=-1){
                tempVaildBool = false;
              }
            }else{
              tempVaildBool = false;
            }
            if(allEdgeIdObjArray.length>0){
              let bool = false;
              for(let j=0;j<allEdgeIdObjArray.length;j++){
                let tempEdgeIdObjArray = allEdgeIdObjArray[j].edgeIdObjArray;
                for(let k=0;k<tempEdgeIdObjArray.length;k++){
                  if(tempEdgeIdObjArray[k].edgeId==ID){
                    bool = true;
                    break;
                  }
                }
                if(bool){
                  break;
                }
              }
              if(bool==false){
                edgeIdObjArray.push({nodeId:nodeId,nextNodeId:nextNodeId,edgeId:ID,smFNode:smFNode,smTNode:smTNode,smEdgeID:smEdgeID,isVaild:tempVaildBool});
                edgeBool = true;
              }
            }else{
              edgeIdObjArray.push({nodeId:nodeId,nextNodeId:nextNodeId,edgeId:ID,smFNode:smFNode,smTNode:smTNode,smEdgeID:smEdgeID,isVaild:tempVaildBool});
              edgeBool = true;
            }
            //绘制弧段
            if(edgeBool==true && geometry!=null){
              let parts = geometry.parts;
              let points = geometry.points;
              let wkt = "LINESTRING(";
              if(points.length>0){
                for(let j=0;j<points.length;j++){
                  let tempPoint = points[j];
                  let lon = tempPoint.x;
                  let lat = tempPoint.y;
                  let lonlat = [lon,lat];
                  wkt += lonlat[0] + " " + lonlat[1] + ",";
                }
                wkt = wkt.substring(0,wkt.length-1);
              }else{
                continue;
              }
              wkt += ")";
              // console.log(wkt);
              //空间数据
              let featureTmp = new WKT().readFeature(wkt);
              //设置属性
              featureTmp.setProperties({
                type:"networkResult",//类型
                geometryType:type,
                fieldNames:fieldNames,
                fieldValues:fieldValues
              });
              let color = 'red';
              if(tempVaildBool){
                color = 'green';
              }
              let style = new Style({
                stroke: new Stroke({
                  color: color,
                  width: 5
                })
              });
              featureTmp.setStyle(style);
              //添加矢量数据
              this.networkAnalystLayer.getSource().addFeature(featureTmp);
            }
          }
        }
      }
      allEdgeIdObjArray.push({nodeId:nodeId,edgeIdObjArray:edgeIdObjArray});
      //获取下一节点弧段
      setTimeout(function(){
        for (let i = 0; i < edgeIdObjArray.length; i++) {
          //根据节点ID和已获取的弧段ID继续遍历连通性的弧段数组并获取新的弧段ID
          allEdgeIdObjArray = that.checkEdgesFeatures(edgesFeatures,edgeIdObjArray[i].nextNodeId,allEdgeIdObjArray,edgeIdObjArray[i].isVaild);
        }
      },1000);
      // for (let i = 0; i < edgeIdObjArray.length; i++) {
      //   //根据节点ID和已获取的弧段ID继续遍历连通性的弧段数组并获取新的弧段ID
      //   allEdgeIdObjArray = this.checkEdgesFeatures(edgesFeatures,edgeIdObjArray[i].nextNodeId,allEdgeIdObjArray,edgeIdObjArray[i].isVaild);
      // }
      return allEdgeIdObjArray;
    },
    getNetworkVersion(params) {//获取网络分析服务
      if(params.layerType=="功能失效分析图"){
        let that = this;
        let taskId = params.taskId;
        let dataType = "";
        if(params.type.name == '供水系统数据源选择') {
          dataType = "供水系统";
        }else if(params.type.name == '供气系统数据源选择') {
          dataType = "供气系统";
        }else if(params.type.name == '供电系统数据源选择') {
          dataType = "供电系统";
        }else if(params.type.name == '交通系统数据源选择') {
          dataType = "交通系统";
        }else if(params.type.name== '通信系统数据源选择') {
          dataType = "通信系统";
        }
        if(dataType){
          let queryParams = {
            page: 1,
            rows: 10,
            dataType:dataType,
            taskId:taskId
          };
          //查询交通网络分析服务版本列表
          getNetworkVersionList(queryParams).then(response => {
            let list = response.data.rows?response.data.rows:[];
            if(list.length>0){
              that.networkUrl = list[0].networkUrl;//网络分析服务url
              that.networkDatasource = list[0].datasource;//网络分析数据源
              that.networkDataset = list[0].dataset;//网络分析数据集
              if(that.networkUrl){
                let tempUrl = that.networkUrl;
                tempUrl = tempUrl.replace("transportationAnalyst-","map-");
                tempUrl = tempUrl.replace("rest/networkanalyst","rest/maps");
                that.networkMapUrl = tempUrl;//网络分析地图服务url
                // //添加网络分析地图服务图层
                // getNetworkLayer(that.map,that.networkMapUrl);
                // //查询源点
                // that.queryNetworkSourceNodeIDs();
              }
            }
            //test
            // that.networkUrl = "http://10.7.208.233:8080/iserver/services/transportationAnalyst-dxPipeNetwork/rest/networkanalyst/dxPipeNetwork_Network@dxPipeNetwork";//网络分析服务url
            // that.networkDatasource = "dxPipeNetwork";//网络分析数据源
            // that.networkDataset = "dxPipeNetwork_Network";//网络分析数据集
            // that.networkUrl = "http://10.7.208.233:8080/iserver/services/map-dxPipeNetwork/rest/maps/dxPipeNetwork_Network@dxPipeNetwork";//网络分析地图服务url
            //test
            // that.networkUrl = "http://10.13.155.192:8090/iserver/services/transportationAnalyst-smxNetwork/rest/networkanalyst/DataSource_Network@DataSource";//网络分析服务url
            // that.networkDatasource = "DataSource";//网络分析数据源
            // that.networkDataset = "DataSource_Network";//网络分析数据集
            // that.networkMapUrl = "http://10.13.155.192:8090/iserver/services/map-smxNetwork/rest/maps/DataSource_Network@DataSource";//网络分析地图服务url
          });
        }
      }
    },
    clearNetwork(){//清空网络分析服务
      this.clearNetworkBool = false;
      if(this.networkFeatureLayer!=null){
        this.networkFeatureLayer.getSource().clear();
      }
      if(this.networkAnalystLayer!=null){
        this.networkAnalystLayer.getSource().clear();
      }
      this.notValidNetworkNodeIdArray = [];//无效节点ID
      this.notValidNetworkEdgeIdArray = [];//无效弧段ID
    },
    setPopupContent(temp){//设置弹窗内容
      let html = "";
      let fieldNames = temp.fieldNames;
      let fieldValues = temp.fieldValues;
      let type = temp.geometryType;
      let fieldArray = [];
      if(type=="POINT"){
        html += "空间类型：点数据<br/>";
        // fieldArray = ["SMID","SMNODEID","ID","TASK_ID","TYPE","LONGITUDE","LATITUDE","NODETYPE"];
        fieldArray = ["SMID","SMNODEID","TYPE","LONGITUDE","LATITUDE"];
      }else if(type=="LINE"){
        html += "空间类型：线数据<br/>";
        // fieldArray = ["SMID","SMLENGTH","SMFNODE","SMTNODE","SMEDGEID","ID","TASK_ID","TYPE","DIRECTION"];
        fieldArray = ["SMID","TYPE","SMLENGTH","SMFNODE","SMTNODE","SMEDGEID"];
      }
      for(let i=0;i<fieldNames.length;i++){
        for(let j=0;j<fieldArray.length;j++){
          let fieldName = fieldNames[i].toUpperCase();//字段名
          let fieldValue = fieldValues[i];
          if(fieldArray[j]==fieldName){
            if(fieldName=="SMNODEID"){
              fieldName = "节点ID";
            }else if(fieldName=="LONGITUDE"){
              fieldName = "经度";
            }else if(fieldName=="LATITUDE"){
              fieldName = "纬度";
            }else if(fieldName=="SMLENGTH"){
              fieldName = "弧段长度（米）";
            }else if(fieldName=="SMFNODE"){
              fieldName = "弧段流入节点ID";
            }else if(fieldName=="SMTNODE"){
              fieldName = "弧段流出节点ID";
            }else if(fieldName=="SMEDGEID"){
              fieldName = "弧段ID";
            }else if(fieldName=="TYPE"){
              fieldName = "类型";
              if(fieldValue==1){
                fieldValue = "地下管网";
              }else if(fieldValue==11){
                fieldValue = "水厂泵房";
              }else if(fieldValue==2){
                fieldValue = "水厂水池";
              }else if(fieldValue==3){
                fieldValue = "燃气-储气罐";
              }else if(fieldValue==14){
                fieldValue = "燃气-门站/场站";
              }else if(fieldValue==15){
                fieldValue = "供气管网";
              }else if(fieldValue==6){
                fieldValue = "变电站";
              }else if(fieldValue==8){
                fieldValue = "电缆线路";
              }else if(fieldValue==12){
                fieldValue = "重要发电厂房";
              }else if(fieldValue==5){
                fieldValue = "道路";
              }else if(fieldValue==4){
                fieldValue = "桥梁";
              }else if(fieldValue==13){
                fieldValue = "通信基站";
              }else if(fieldValue==9){
                fieldValue = "通信室内设备";
              }
            }
            html += fieldName + "："+fieldValue+"<br/>";
            break;
          }
        }
      }
      document.getElementById(this.str+'-popup-content').innerHTML = html;
      //显示弹出窗口
      document.getElementById(this.str+"-popup").style.display="block";
    },
    showBoundingExtent(coordinates){//缩放到区域位置
      //console.log("缩放到区域位置");
      if (coordinates!=null && coordinates.length > 1) {
        const extent = boundingExtent(coordinates);
        //this.map.getView().fit(extent, {duration: 1000, padding: [50, 50, 50, 50]});
        this.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
        //获取默认位置
        this.center = this.map.getView().getCenter();
        this.zoom = this.map.getView().getZoom();
      }
    },
    /////////////////////////////////////////////////////////////////////////////////////经纬度查询图层数据start
    //根据经纬度查询当前显示的图层要素数据
    getAllShowLayerFeatureDataByLonLat(lonlat){
      if(this.popupInfoLayer!=null && lonlat!=null && lonlat.length==2){
        this.popupInfoLayer.setPosition(undefined);//隐藏弹窗
        this.showLayerNum = this.allDataTypeInfoArray.length;//当前显示的图层数量
        this.queryLayerNum = 0;//已查询的图层数量
        this.resultDataTypeInfo = null;//已查询到图层要素结果的数据类型信息
        this.resultDataId = null;//已查询到的图层要素主键ID
        this.resultDataFeature = null;//已查询到的图层要素数据
        //清空选中要素高亮显示图层
        this.selectFeatureLayer.getSource().clear();
        if(this.showLayerNum>0){
          //正在查询
          this.loading = ElLoading.service({
            lock: true,
            text: '正在查询...',
            background: 'rgba(0, 0, 0, 0.7)',
          });
          for(let i=0;i<this.allDataTypeInfoArray.length;i++){
            let dataTypeInfo = this.allDataTypeInfoArray[i];
            //经纬度查询图层数据
            this.queryFeatureByLonLat(dataTypeInfo.database,dataTypeInfo.table,lonlat,dataTypeInfo,dataTypeInfo.sqlText);
          }
        }
      }else{
        if(this.popupInfoLayer!=null) {
          this.popupInfoLayer.setPosition(undefined);//隐藏弹窗
        }
      }
    },
    queryFeatureByLonLat(databaseName,tableName,lonlat,dataTypeInfo,sql){//经纬度查询图层数据
      if(databaseName && tableName && lonlat!=null && lonlat.length==2 && dataTypeInfo){
        let datasource = databaseName;
        let dataset = tableName;
        // let geomText = "POINT("+lonlat[0]+" "+lonlat[1]+")";
        // //空间数据
        // let feature = new WKT().readFeature(geomText);
        let zoom = this.map.getView().getZoom();
        let temp = Math.pow(2,(18 - zoom));
        //点生成圆多边形
        // let meter = 3 * temp;//米
        let meter = 5 * temp;//米
        let degree = meterToDegree(meter);
        let circle = new Circle(lonlat, degree); // 用圆心和半径确定一个圆
        let polygon = new fromCircle(circle) // 得到一个多边形
        let feature = new Feature({
          geometry: polygon
        });
        //添加矢量数据
        // this.selectFeatureLayer.getSource().addFeature(feature);//选中要素高亮显示图层
        this.queryFeatureByGeometry(datasource,dataset,feature,dataTypeInfo,lonlat,sql);//几何查询
      }
    },
    queryFeatureByGeometry(datasource,dataset,feature,dataTypeInfo,lonlat,sql){//几何查询
      let that = this;
      let url = iServerHttp() + "/iserver/services/data-"+datasource+"/rest/data";
      let polygon = feature.getGeometry();
      let geometryParam = new GetFeaturesByGeometryParameters({
        datasetNames: [datasource+":"+dataset],
        geometry: polygon,
        spatialQueryMode: "INTERSECT",
        attributeFilter:sql,//查询过滤条件
      });
      new FeatureService(url).getFeaturesByGeometry(geometryParam, function (serviceResult) {
        console.log("dataset"+dataset);
        console.log(serviceResult.result);
        if(serviceResult.result){
          let features = serviceResult.result.features.features;
          if(features && features.length>0){
            console.log(features);
            console.log(features[0].properties);
            let fieldId = dataTypeInfo.fieldId.toUpperCase();//主键ID字段名
            //主键ID
            let id = features[0].properties[fieldId];
            if(that.resultDataTypeInfo){//已查询到图层要素结果的数据类型信息
              if(that.resultDataTypeInfo.zIndex < dataTypeInfo.zIndex){//图层顺序大的优先查询
                that.resultDataTypeInfo = dataTypeInfo;
                that.resultDataId = id;
                that.resultDataFeature = features[0];
              }
            }else{
              that.resultDataTypeInfo = dataTypeInfo;
              that.resultDataId = id;
              that.resultDataFeature = features[0];
            }
          }
        }
        that.queryLayerNum = that.queryLayerNum + 1;//已查询的图层数量
        console.log("queryLayerNum:"+that.queryLayerNum+"--"+that.showLayerNum);
        if(that.queryLayerNum==that.showLayerNum){//查询完毕
          //根据类型显示弹窗
          that.setPopupContentByType(lonlat);
          //查询完毕
          that.loading.close();
        }
      });
    },
    setPopupContentByType(lonlat){//根据类型显示弹窗
      console.log("根据类型显示点击要素属性弹窗");
      let dataTypeInfo = this.resultDataTypeInfo;
      console.log(dataTypeInfo);
      if(dataTypeInfo){//有查询要素数据
        let database = dataTypeInfo.database;
        let id = this.resultDataId;//主键ID
        let features = this.resultDataFeature;
        let properties = features.properties;
        console.log(dataTypeInfo);
        console.log(id);
        console.log(features);
        console.log(properties);
        let temp = {
          id:id,
          typeCode:dataTypeInfo.code,
          database:dataTypeInfo.database,
        }
        //获取显示内容
        let innerHTML = this.getPopupContent(dataTypeInfo,properties);
        console.log("innerHTML----"+innerHTML);
        //显示地图弹窗
        document.getElementById(this.str+'-popup-content').innerHTML = innerHTML;
        //显示弹出窗口
        document.getElementById(this.str+"-popup").style.display="block";
        this.popupInfoLayer.setPosition(lonlat);
      }
    },
    //获取要素属性详情html
    getPopupContent(dataTypeInfo,properties){
      let html = "";
      if(dataTypeInfo && properties){
        let datasource = dataTypeInfo.database;
        let dataset = dataTypeInfo.table;
        let columns = null;
        let disasterFieldName = "";//破坏状态修正值
        let functionalFieldName = "";//功能失效状态修正值
        if(dataTypeInfo.seismicInputMode=="0"){
          if(dataTypeInfo.intensity == 'ld1') {
            disasterFieldName = "disaster_rate6_state_correction";
            functionalFieldName = "functional_failure6_correct";
          }else if(dataTypeInfo.intensity == 'ld2'){
            disasterFieldName = "disaster_rate7_state_correction";
            functionalFieldName = "functional_failure7_correct";
          }else if(dataTypeInfo.intensity == 'ld3'){
            disasterFieldName = "disaster_rate8_state_correction";
            functionalFieldName = "functional_failure8_correct";
          }else if(dataTypeInfo.intensity == 'ld4'){
            disasterFieldName = "disaster_rate9_state_correction";
            functionalFieldName = "functional_failure9_correct";
          }else if(dataTypeInfo.intensity == 'ld5'){
            disasterFieldName = "disaster_rate10_state_correction";
            functionalFieldName = "functional_failure10_correct";
          }
        }else{
          disasterFieldName = "disaster_rate6_state";
          functionalFieldName = "functional_failure6_correct";
        }
        if(dataset=="fxqh_smx_evaluation_results"){//生命线计算结果点数据图层
          html = "空间类型：点数据<br>";
          columns = [
            {fieldName:"id",name:"id"},
            {fieldName:"type",name:"类型"},
            {fieldName:disasterFieldName,name:"破坏等级"},
            {fieldName:functionalFieldName,name:"功能失效状态"},
            {fieldName:"longitude",name:"经度"},
            {fieldName:"latitude",name:"纬度"},
          ];
          //设置字段名大写
          for(let i=0;i<columns.length;i++){
            columns[i].fieldName = columns[i].fieldName.toUpperCase();//转换大写字母
          }
        }else if(dataset=="fxqh_smx_evaluation_results_line"){//生命线计算结果线数据图层
          html = "空间类型：线数据<br>";
          columns = [
            {fieldName:"id",name:"id"},
            {fieldName:"type",name:"类型"},
            {fieldName:disasterFieldName,name:"破坏等级"},
            {fieldName:functionalFieldName,name:"功能失效状态"},
          ];
          //设置字段名大写
          for(let i=0;i<columns.length;i++){
            columns[i].fieldName = columns[i].fieldName.toUpperCase();//转换大写字母
          }
        }
        if(columns){
          for(let i=0;i<columns.length;i++){
            let fieldName = columns[i].fieldName;
            let name = columns[i].name;
            let value = properties[fieldName];
            if(name=="类型"){
              if(value==1){
                value = "地下管网";
              }else if(value==11){
                value = "水厂泵房";
              }else if(value==2){
                value = "水厂水池";
              }else if(value==3){
                value = "燃气-储气罐";
              }else if(value==14){
                value = "燃气-门站/场站";
              }else if(value==15){
                value = "供气管网";
              }else if(value==6){
                value = "变电站";
              }else if(value==8){
                value = "电缆线路";
              }else if(value==12){
                value = "重要发电厂房";
              }else if(value==5){
                value = "道路";
              }else if(value==4){
                value = "桥梁";
              }else if(value==13){
                value = "通信基站";
              }else if(value==9){
                value = "通信室内设备";
              }
            }
            html += name + "：" + value + "<br>";
          }
        }
      }

      return html;
    },
    /////////////////////////////////////////////////////////////////////////////////////经纬度查询图层数据end
  } 
})
</script>